package logic

import (
	"context"
	"goods_srv/goods"
	"goods_srv/internal/svc"
	"goods_srv/models/mysqlinit"

	"github.com/zeromicro/go-zero/core/logx"
)

type ReleaseHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewReleaseHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReleaseHouseLogic {
	return &ReleaseHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ReleaseHouseLogic) ReleaseHouse(in *goods.ReleaseHouseRequest) (*goods.ReleaseHouseResponse, error) {
	// todo: add your logic here and delete this line
	var users mysqlinit.User
	mysqlinit.DB.Debug().Where("id = ?", in.UserId).Find(&users)
	if users.ID == 0 {
		logx.Error("不存在此用户，无法发布房源")
	}
	house := mysqlinit.House{

		UserId:     int(in.UserId),
		HouseTitle: in.HouseTitle,
		HouseRent:  float64(in.HouseRent),
		Address:    in.Address,
		Community:  in.Community,
		FloorCode:  in.FloorCode,
		FloorNum:   int(in.FloorNum),
		HouseArea:  int(in.HouseArea),
		Status:     in.Status,
	}
	mysqlinit.DB.Debug().Create(&house)
	return &goods.ReleaseHouseResponse{
		Id: int64(house.ID),
	}, nil
}
